package com.ruoyi.project.online_experiment.controller;

import java.util.List;

import com.ruoyi.project.online_experiment.domain.Echart;
import com.ruoyi.project.online_experiment.domain.OnlineExperiment;
import com.ruoyi.project.online_experiment.service.IOnlineExperimentService;

import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author lvyongwei
 * @date 2020-04-14
 */
@Controller
@RequestMapping("/system/onlineExperiment")
public class OnlineExperimentController extends BaseController
{
    private String prefix = "system/onlineExperiment";

    @Autowired
    private IOnlineExperimentService onlineExperimentService;

    @RequiresPermissions("system:onlineExperiment:view")
    @GetMapping()
    public String experiment()
    {
        return prefix + "/onlineExperiment";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:onlineExperiment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OnlineExperiment onlineExperiment)
    {
        startPage();
        List<OnlineExperiment> list = onlineExperimentService.selectOnlineExperimentList(onlineExperiment);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:onlineExperiment:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OnlineExperiment onlineExperiment)
    {
        List<OnlineExperiment> list = onlineExperimentService.selectOnlineExperimentList(onlineExperiment);
        ExcelUtil<OnlineExperiment> util = new ExcelUtil<OnlineExperiment>(OnlineExperiment.class);
        return util.exportExcel(list, "experiment");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:onlineExperiment:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OnlineExperiment onlineExperiment)
    {
        return toAjax(onlineExperimentService.insertOnlineExperiment(onlineExperiment));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{onlineExperimentId}")
    public String edit(@PathVariable("onlineExperimentId") Long onlineExperimentId, ModelMap mmap)
    {
        OnlineExperiment onlineExperiment = onlineExperimentService.selectOnlineExperimentById(onlineExperimentId);
        mmap.put("onlineExperiment", onlineExperiment);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:onlineExperiment:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OnlineExperiment onlineExperiment)
    {
        return toAjax(onlineExperimentService.updateOnlineExperiment(onlineExperiment));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:onlineExperiment:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(onlineExperimentService.deleteOnlineExperimentByIds(ids));
    }


    /**
     * 教師指派頁面
     * @param onlineExperimentId
     * @param mmap
     * @return
     */
    @GetMapping("/assign/{onlineExperimentId}")
    public String assign(@PathVariable("onlineExperimentId") Long onlineExperimentId, ModelMap mmap)
    {
        OnlineExperiment onlineExperiment = onlineExperimentService.selectOnlineExperimentById(onlineExperimentId);
        mmap.put("onlineExperiment", onlineExperiment);
        return prefix + "/assign";
    }


    /**
     * 获取专业对应的教师
     * @param user
     * @return
     */
    @GetMapping("/getTeacher")
    @ResponseBody
    public List<User> assign(User user)
    {
         List<User> users=onlineExperimentService.getAllUser(user);
         return users;
    }



    /**
     * 获取eachart图表
     * @param modelMap
     * @return
     */
    @GetMapping("/getEachart")
    public String getEachart(ModelMap modelMap){
        return prefix+"/getEachart";
    }

    @GetMapping("/getEchart2")
    @ResponseBody
    public Echart getEchart(){
        Echart echart=onlineExperimentService.getAllEachart();
        return echart;
    }

    /**
     * 获取图表项      获取项目中布置的实验的个数
     * @return
     */
    @GetMapping("/getEchart3")
    @ResponseBody
    public List<Echart> getAllCount(){
        List<Echart> list=onlineExperimentService.getAllCount();
        return list;
    }

    /**
     * 获取图表项      获取项目中布置的实验的个数
     * @return
     */
    @GetMapping("/getEchart4")
    @ResponseBody
    public List<Echart> getAllCount2(){
        List<Echart> list=onlineExperimentService.getPersonCount();
        return list;
    }

}
